package com.ss.android.account.v2.view;

import android.animation.AnimatorSet;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bytedance.common.utility.UIUtils;
import com.bytedance.common.utility.collection.WeakHandler;
import com.bytedance.frameworks.b.a.ComponentsManifest;
import com.ss.android.account.bus.event.f;
import com.ss.android.account.customview.a.e;
import com.ss.android.account.d.a;
import com.ss.android.account.d.c;
import com.ss.android.account.d.d;
import com.ss.android.account.e.AccountAnimatorHelper;
import com.ss.android.account.v2.bb;
import com.ss.android.article.browser.R;
import com.ss.android.common.ui.view.AlphaImageView;
import com.ss.android.messagebus.SubscriptionRouter;

import im.quar.autolayout.utils.AutoUtils;
import java.util.ArrayList;
import java.util.List;

public final class h extends a implements WeakHandler.Callback, d {
    View b;
    EditText c;
    EditText d;
    TextView e;
    TextView f;
    View g;
    ImageView h;
    List i;
    List j;
    AnimatorSet k;
    int l;
    WeakHandler m;
    private TextView n;
    private TextView o;
    private Button p;
    private ProgressDialog q;
    private e r;
    private RelativeLayout s;
    private boolean t;
    private View u;
    private View.OnTouchListener v;

    public h() {

        this.i = new ArrayList();
        this.j = new ArrayList();
        this.l = 0;
        this.v = new p(this);
    }

    static c a(h arg1) {
        return ((a)arg1).a;
    }

    @NonNull
    public final c a(Context arg2) {
        return new com.ss.android.account.v2.c.d(arg2);
    }

    public final void a() {
        this.m = new WeakHandler(((WeakHandler.Callback)this));
        this.getArguments().getString("extra_source");
        this.r = new e(this.getActivity());
    }

    public final void a(int arg6) {
        if(arg6 == 0) {
            if(!this.o.isEnabled()) {
                this.o.setEnabled(true);
            }

            this.o.setText(this.getString(com.ss.android.article.browser.R.string.resend));
        }
        else {
            if(this.o.isEnabled()) {
                this.o.setEnabled(false);
            }

            this.o.setText(this.getString(com.ss.android.article.browser.R.string.resend_info, new Object[]{Integer.valueOf(arg6)}));
        }
    }

    public final void a(View arg3) {
        this.b = arg3.findViewById(com.ss.android.article.browser.R.id.hg);
        this.n = arg3.findViewById(com.ss.android.article.browser.R.id.hf);
        this.o = arg3.findViewById(com.ss.android.article.browser.R.id.hm);
        this.c = arg3.findViewById(com.ss.android.article.browser.R.id.hh);
        this.d = arg3.findViewById(com.ss.android.article.browser.R.id.hl);
        this.e = arg3.findViewById(com.ss.android.article.browser.R.id.hj);
        this.f = arg3.findViewById(com.ss.android.article.browser.R.id.ho);
        arg3.findViewById(com.ss.android.article.browser.R.id.hq);
        this.p = arg3.findViewById(com.ss.android.article.browser.R.id.hp);
        this.u = this.getActivity().getWindow().getDecorView().findViewById(16908290);
        this.p.setText(ComponentsManifest.findComponent(bb.class).b().b());
    }

    final void a(CharSequence arg5, CharSequence arg6) {
        boolean v0 = !TextUtils.isEmpty(arg5) || !TextUtils.isEmpty(arg6) ? true : false;
        SubscriptionRouter.c(new f(v0));
        int v0_1 = arg5.length() >= 11 && arg5.charAt(0) != 43 || arg5.length() >= 14 ? 1 : 0;
        if(v0_1 == 0 || !android.support.design.a.b(arg6)) {
            if(!this.t) {
                this.t = true;
                this.p.setBackgroundResource(com.ss.android.article.browser.R.drawable.a6);
            }
        }
        else if(this.t) {
            this.t = false;
            this.p.setBackgroundResource(com.ss.android.article.browser.R.drawable.a7);
        }
    }

    public final void a(String arg3) {
        UIUtils.showImageToast(this.getActivity(), R.drawable.close_popup_textpage, arg3);
    }

    public final void a(String arg4, String arg5, int arg6, com.ss.android.account.customview.a.e.a arg7) {
        e v0 = this.r;
        if(v0.a.getSupportFragmentManager().findFragmentByTag("captcha") == null) {
            v0.c = com.ss.android.account.activity.mobile.a.a(arg4, arg6, new com.ss.android.account.activity.mobile.a.a$a(v0, arg7, arg6));
            v0.c.show(v0.a.getSupportFragmentManager(), "captcha");
        }
        else {
            v0.a(arg4, arg5);
        }
    }

    static c b(h arg1) {
        return ((a)arg1).a;
    }

    public final void b() {
        this.c.setOnTouchListener(this.v);
        this.d.setOnTouchListener(this.v);
        this.o.setOnClickListener(new i(this));
        this.c.addTextChangedListener(new j(this));
        this.d.addTextChangedListener(new k(this));
        this.p.setOnClickListener(new l(this));
        if(this.h != null) {
            this.h.setOnClickListener(new m(this));
        }
    }

    public final void b(View arg14) {
        int v11 = -2;
        this.s = arg14.findViewById(com.ss.android.article.browser.R.id.hr);
        FragmentActivity v1 = this.getActivity();
        RelativeLayout v2 = this.s;
        List v3 = this.i;
        c v0 = ((a)this).a;
        LinearLayout v4 = new LinearLayout(((Context)v1));
        v4.setGravity(17);
        v4.setOrientation(LinearLayout.HORIZONTAL);
        int v5 = ((Context)v1).getResources().getDimensionPixelSize(R.dimen.bk);
        int v6 = ((Context)v1).getResources().getDimensionPixelOffset(R.dimen.bj);
        v5 = AutoUtils.scaleValue(v5);
        v6 = AutoUtils.scaleValue(v6);
        com.ss.android.account.e.g v7 = new com.ss.android.account.e.g(((com.ss.android.account.e.h)v0));
        List v0_1 = android.support.design.a.g();
        ArrayList v8 = new ArrayList();
        if((v0_1.isEmpty()) || (v0_1.contains("weixin"))) {
            AlphaImageView v9 = new AlphaImageView(((Context)v1));
            ((ImageView)v9).setId(com.ss.android.article.browser.R.id.aa);
            ((ImageView)v9).setImageResource(com.ss.android.article.browser.R.drawable.icon_wechat);
            ((ImageView)v9).setOnClickListener(((View.OnClickListener)v7));
            v4.addView(((View)v9), new LinearLayout.LayoutParams(v5, v5));
            v3.add(v9);
            ((List)v8).add(v9);
        }

        if((v0_1.isEmpty()) || (v0_1.contains("qzone_sns"))) {
            AlphaImageView v0_2 = new AlphaImageView(((Context)v1));
            ((ImageView)v0_2).setId(com.ss.android.article.browser.R.id.a6);
            ((ImageView)v0_2).setImageResource(com.ss.android.article.browser.R.drawable.icon_qq);
            ((ImageView)v0_2).setOnClickListener(((View.OnClickListener)v7));
            LinearLayout.LayoutParams v7_1 = new LinearLayout.LayoutParams(v5, v5);
            v7_1.leftMargin = v6;
            v4.addView(((View)v0_2), ((ViewGroup.LayoutParams)v7_1));
            v3.add(v0_2);
            ((List)v8).add(v0_2);
        }

        HorizontalScrollView v0_3 = new HorizontalScrollView(((Context)v1));
        v0_3.addView(((View)v4), new FrameLayout.LayoutParams(v11, v11));
        RelativeLayout.LayoutParams v1_1 = new RelativeLayout.LayoutParams(v11, v11);
        v1_1.addRule(13);
        v2.addView(((View)v0_3), ((ViewGroup.LayoutParams)v1_1));
        v0_3.setId(com.ss.android.article.browser.R.id.icon_container);
        this.g = (View) v3.get(0);
        this.n.setText((( com.ss.android.account.v2.c.d)this.a).e.a(this.getArguments().getString("extra_title_type")));
        this.h = this.s.findViewById(com.ss.android.article.browser.R.id.a3);
        this.a(this.c.getText(), this.d.getText());
    }

    public final void b(String arg3) {
        this.c.setText(((CharSequence)arg3));
        this.c.setSelection(arg3.length());
        if(android.support.design.a.isTelephoneNo(((CharSequence)arg3))) {
            this.p.setEnabled(true);
        }
    }

    static c c(h arg1) {
        return arg1.a;
    }

    public final void c() {
        if(this.q == null) {
            this.q = com.ss.android.j.b.createProgressDialog(this.getActivity());
            this.q.setOnDismissListener(new o(this));
        }

        this.q.show();
    }

    public final void c(String arg3) {
        this.d.setBackgroundResource(com.ss.android.article.browser.R.drawable.a_);
        this.f.setText(((CharSequence)arg3));
        this.f.setVisibility(View.VISIBLE);
        AccountAnimatorHelper.createTranslationXAnimator(this.f).start();
    }

    public final void d() {
        if(this.q != null && (this.q.isShowing())) {
            this.q.dismiss();
        }
    }

    final void d(String arg2) {
        (( com.ss.android.account.v2.c.d)this.a).b(arg2);
    }

    public final void e() {
        com.ss.android.account.activity.mobile.a v3 = null;
        e v0 = this.r;
        if(v0.c != null) {
            v0.c.dismiss();
            v0.c = v3;
        }

        if(v0.d != null) {
            v0.d.a = true;
            v0.d = ((com.ss.android.account.v2.b.f)null);
        }
    }

    public final void f() {
        this.b.setBackgroundResource(com.ss.android.article.browser.R.drawable.a_);
        this.e.setVisibility(View.VISIBLE);
        AccountAnimatorHelper.createTranslationXAnimator(this.e).start();
    }

    public final void handleMsg(Message message) {
        int v4 = 1000;
        FragmentActivity v0 = this.getActivity();
        if(v0 != null && !((Activity)v0).isFinishing()) {
            if(message.what != 1000) {
            }
            else if(android.support.design.a.d(this.u)) {
                this.c.setFocusableInTouchMode(true);
                this.d.setFocusableInTouchMode(true);
                if(this.l == 0) {
                    this.c.requestFocus();
                }
                else if(this.l == 1) {
                    this.d.requestFocus();
                }

                this.m.removeMessages(v4);
            }
            else {
                this.m.sendEmptyMessageDelayed(v4, 50);
            }
        }
    }

    public final void onDestroyView() {
        super.onDestroyView();
        if(this.k != null && (this.k.isRunning())) {
            this.k.cancel();
        }
    }
}

